package utils

import (
	"regexp"
	"strings"
)

func StartWith(str string, subStr string) bool {
	return strings.Index(str, subStr) == 0
}

func EndWith(str string, subStr string) bool {
	exp, _ := regexp.Compile(regexp.QuoteMeta(subStr) + "$")
	return len(exp.FindString(str)) > 0
}

func SubString(str string, start, end int) string {
	rs := []rune(str)
	length := len(rs)

	if start < 0 || start > length {
		return ""
	}

	if end < start || end > length {
		return ""
	}

	return string(rs[start:end])
}
